#ifndef BRATCONN_H
#define BRATCONN_H

#include "connect.h"

// SNA: Vulnerability #2003021801
#if (CONNECT_IBUF != CONNECT_OBUF)
#error "CONNECT_IBUF and CONNET_OBUF *must* be identical!"
#endif

#define APP1		(uint8)'B'
#define APP2		(uint8)'r'

#define GAMEID	1				// Baccarat
#define MACHID	(uint8)0		// Baccarat only has one "machine"

enum TiePayoutOdds
{
	NINE_TO_ONE  = 1,
	EIGHT_TO_ONE = 2,
};

class BratHand;

class BratConnection : public Connection
{
	public:
		BratConnection(Server*server, SOCKET client);
		~BratConnection();

		void msgStart();
		void msgAdd(uint8 Byte);
		void msgAdd(int32 SignedLong);
		uint8* msgGetBuf();
		void msgReleaseBuf(int32 Amt);
		void msgEnd();

        #ifdef FORCEDSHOE 
        String  GetPID() {return m_pid;}
        #endif


		bool8	trackGetBalance(int32 *);
		int32	trackAdjustBalance(int32);	// + increases  - decreases
		bool8	trackGetPlayerLimits(int32* minBet, int32* maxBet,
					int32* compFactor);
		bool8	trackGame(BratHand* Bank, BratHand* Player,
					int32* Bets, int32* Payouts, int32 NumBetsPayouts,
					int32 Commission, int32 Outcome, int32 BalanceAdjust,
					int32* Balance);
		void	trackaddBadPacket(int32 error_reason, char MessageType, char *msgbuf, int32 msglen);
		bool8	trackGetOptions(int32 * tiePayout);
		int32	trackValidateLogin();
		int32	trackValidateSession();

		void	trackLogoutSession();	// CSN-7075: New Authentication

		TiePayoutOdds getTiePayoutOdds() { return tiePayout; }

	protected:
		bool8	getResponse();
		void	handleLogin(int32 len);

		void	sendStopMsg();

		bool8	parseCasinoLogin(int32, int32*);
		bool8	parseUnicodeCasinoLogin(int32, int32*);
		void	removeCasinoSpecific();

		int32	encode(uint8*, uint8*, int32);
		int32	decode(uint8*, uint8*, int32);

		int32	msgRemove(uint8*, int32*);

		bool getOptions();
		
		void	allocateXMLTranslator( XMLTranslator** target );

	protected:
		int32 loggedOn;
		void* casinoSpecific;
		int32 minBet, maxBet;

		TiePayoutOdds tiePayout;

		int32 compFactor;
		int32 msglen;
		uint8 msgbuf[CONNECT_IBUF];		// SNA: Vulnerability #2003021801

        #ifdef FORCEDSHOE       //RPF 20100317 When forcing the shue now filter by pid
        String  m_pid;
        #endif


	// [AO 2008-01-16] Refactoring for HA
	private:
		bool ValidateSession();
};

#endif
